<?php
namespace App\Services\Wxxcx;

use Illuminate\Support\Facades\DB;

class SceneService extends BaseService
{
    /**
     * 场景
     */

    /**
     * 列表
     */
    public function getList()
    {
        $db = $this->dbConn($this->dbScene)->where('del', 1);
        $total = $db->count();
        $res = $db->skip(0)->take(100)
            ->orderBy('id', 'asc')
            ->get();
        if (!count($res)) {
            return $this->toback(-2, '没有记录');
        }
        $arys = [];
        foreach ($res as $v) {
            $v = (array) $v;
            $arys[] = [
                'id' => $v['id'],
                'title' => $v['title'],
                'icon' => file_exists($v['icon']) ? $v['icon'] : '',
                'thumb' => file_exists($v['thumb']) ? $v['thumb'] : '',
                'prefixUrl' => env('DOMAIN').'/',
            ];
        }
        return $this->toback(0, '', $arys, $total);
    }

    /**
     * 内容列表
     * @param int $scene_id
     */
    public function cntList($scene_id)
    {
        $res = $this->dbConn($this->dbSceneCnt)->where('del', 1)
            ->where('scene_id', $scene_id)
            ->skip(0)->take(100)
            ->orderBy('id', 'asc')
            ->get();
        if (!count($res)) {
            return $this->toback(-2, '没有记录');
        }
        $arys = [];
        foreach ($res as $v) {
            $v = (array) $v;
            $arys[] = [
                'id' => $v['id'],
                'type' => $v['type'],
                'prefixUrl' => env('DOMAIN').'/',
                'cnt' => $v['cnt'],
            ];
        }
        return $this->toback(0, '', $arys);
    }
}